package logic

import (
	"context"
	"tieba/tiebarpc/tiebarpc"

	"tieba/api/internal/svc"
	"tieba/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type TypeAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTypeAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TypeAddLogic {
	return &TypeAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TypeAddLogic) TypeAdd(req *types.TypeAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.TieBaRpc.TypeAdd(l.ctx, &tiebarpc.TypeAddRequest{
		TypeName: req.TypeName,
		Number:   req.Number,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "创建分类成功",
		Data:    add,
	}, nil
	return
}
